/**
 * Copyright (c) 2016-2021 by the respective copyright holders.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package com.zsmartsystems.zigbee.dongle.xbee.internal.protocol;

import java.util.HashMap;
import java.util.Map;

/**
 * Class to implement the XBee Enumeration <b>DeliveryStatus</b>.
 * <p>
 * Note that this code is autogenerated. Manual changes may be overwritten.
 *
 * @author Chris Jackson - Initial contribution of Java code generator
 */
public enum DeliveryStatus {
    /**
     * Default unknown value
     */
    UNKNOWN(-1),

    /**
     * [0]
     */
    SUCCESS(0x0000),

    /**
     * [1]
     */
    MAC_ACK_FAILURE(0x0001),

    /**
     * [2]
     */
    CCA_FAILURE(0x0002),

    /**
     * [21]
     */
    INVALID_DESTINATION_ENDPOINT(0x0015),

    /**
     * [33]
     */
    NETWORK_ACK_FAILURE(0x0021),

    /**
     * [34]
     */
    NOT_JOINED_TO_NETWORK(0x0022),

    /**
     * [35]
     */
    SELF_ADDRESSED(0x0023),

    /**
     * [36]
     */
    ADDRESS_NOT_FOUND(0x0024),

    /**
     * [37]
     */
    ROUTE_NOT_FOUND(0x0025),

    /**
     * [38]
     */
    BROADCAST_SOURCE_FAILED_TO_HEAR_A_NEIGHBOR_RELAY_THE_MESSAGE(0x0026),

    /**
     * [43]
     */
    INVALID_BINDING_TABLE_INDEX(0x002B),

    /**
     * [44]
     */
    RESOURCE_ERROR(0x002C),

    /**
     * [45]
     */
    ATTEMPTED_BROADCAST_WITH_APS_TRANSMISSION(0x002D),

    /**
     * [46]
     */
    ATTEMPTED_UNICAST_WITH_APS_TRANSMISSION(0x002E),

    /**
     * [50]
     */
    RESOURCE_ERROR_2(0x0032),

    /**
     * [116]
     */
    DATA_PAYLOAD_TOO_LARGE(0x0074),

    /**
     * [117]
     */
    INDIRECT_MESSAGE_UNREQUESTED(0x0075);

    /**
     * A mapping between the integer code and its corresponding type to
     * facilitate lookup by code.
     */
    private static Map<Integer, DeliveryStatus> codeMapping;

    private int key;

    private DeliveryStatus(int key) {
        this.key = key;
    }

    private static void initMapping() {
        codeMapping = new HashMap<Integer, DeliveryStatus>();
        for (DeliveryStatus s : values()) {
            codeMapping.put(s.key, s);
        }
    }

    /**
     * Lookup function based on the type code. Returns null if the code does not exist.
     *
     * @param deliveryStatus
     *            the code to lookup
     * @return enumeration value.
     */
    public static DeliveryStatus getDeliveryStatus(int deliveryStatus) {
        if (codeMapping == null) {
            initMapping();
        }

        if (codeMapping.get(deliveryStatus) == null) {
            return UNKNOWN;
        }

        return codeMapping.get(deliveryStatus);
    }

    /**
     * Returns the XBee protocol defined value for this enum
     *
     * @return the XBee enumeration key
     */
    public int getKey() {
        return key;
    }
}
